package clientGui;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextField;

import client.Client;

public class ChatPanel extends javax.swing.JPanel
{
	private JTextArea chatArea;
	private JScrollPane scrollPane;
	public void printMessage(String author, String msg)
	{
		chatArea.append(author + ": " + msg +"\n");
	}
	
	public ChatPanel()
	{
		setLayout(new BorderLayout(0, 0));
		inputField = new JTextField();
		add(inputField, BorderLayout.SOUTH);
		inputField.setColumns(10);
		inputField.addActionListener(
			new ActionListener()
			{
				@Override
				public void actionPerformed(ActionEvent e)
				{
					Client.handleUserInput(inputField.getText());
					inputField.setText("");
				}
				
			});
		chatArea = new JTextArea();
		chatArea.setLineWrap(true);
		chatArea.setWrapStyleWord(true);
		chatArea.setEditable(false);
		scrollPane = new JScrollPane(chatArea);
		add(scrollPane, BorderLayout.CENTER);
	}
	private static final long serialVersionUID = 3904650755390653201L;
	private JTextField inputField;
	public void disableInput()
	{
		inputField.setEnabled(false);
	}
}
